/*
 * Tencent is pleased to support the open source community by making ovCompose available.
 * Copyright (C) 2025 THL A29 Limited, a Tencent company. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tencent.compose.sample.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState

/**
 * 导航目的地枚举
 */
enum class NavDestination {
    HOME,           // 主页列表
    BREAKPOINT,     // 断点 Demo
    MEDIA_QUERY,    // 媒体查询 Demo
    CANIUSE         // CanIUse 能力检测 Demo
}

/**
 * 简单的导航控制器
 */
class SimpleNavController(private val currentDestination: MutableState<NavDestination>) {
    fun navigate(destination: NavDestination) {
        currentDestination.value = destination
    }

    fun navigateBack() {
        currentDestination.value = NavDestination.HOME
    }

    fun getCurrentDestination(): NavDestination = currentDestination.value
}

/**
 * 导航图 - 根据当前目的地显示对应页面
 */
@Composable
fun NavGraph(
    navController: SimpleNavController,
    homeScreen: @Composable () -> Unit,
    breakpointScreen: @Composable () -> Unit,
    mediaQueryScreen: @Composable () -> Unit,
    canIUseScreen: @Composable () -> Unit
) {
    when (navController.getCurrentDestination()) {
        NavDestination.HOME -> homeScreen()
        NavDestination.BREAKPOINT -> breakpointScreen()
        NavDestination.MEDIA_QUERY -> mediaQueryScreen()
        NavDestination.CANIUSE -> canIUseScreen()
    }
}
